package jmine.tec.database.pack;

import java.util.Collection;

import jmine.tec.utils.dependency.DependencyGraph;
import jmine.tec.utils.register.Receiver;

/**
 * @author lundberg
 */
public class PackCreator implements Receiver<PackPopulator> {

    private final DependencyGraph<PackPopulator> populators = new DependencyGraph<PackPopulator>();

    /**
     * Cria um pacote
     * 
     * @return pack
     * @throws PackException PackException
     */
    public Pack createPack() throws PackException {
        Pack pack = new DefaultPack();
        for (PackPopulator populator : this.populators.getTopologicalOrder()) {
            populator.populate(pack);
        }
        return pack;
    }

    /**
     * {@inheritDoc}
     */
    public void register(Collection<? extends PackPopulator> registers) {
        this.populators.addValues(registers);
    }
}
